package me.ereach.streams;

import java.util.Comparator;
import java.util.List;

public class Main10SimpleReducers {
    public static void main(String[] args) {
        List<Movie> movies = List.of(
                new Movie("a", 10),
                new Movie("b", 15),
                new Movie("c", 20)
        );

        // get count of movies
        System.out.println("===Count");
        System.out.println(movies.stream().count());

        // check if exists for the predicate
        System.out.println("===anyMatch");
        var rst = movies.stream()
                .anyMatch(m -> m.getLikes() > 10);
        System.out.println(rst);

        // check if all match the predicate
        System.out.println("===allMatch");
        rst = movies.stream()
                .allMatch(m -> m.getLikes() > 10);
        System.out.println(rst);

        // check if none match the predicate
        System.out.println("===noneMatch");
        rst = movies.stream()
                .noneMatch(m -> m.getLikes() > 10);
        System.out.println(rst);

        // return the first movie obj
        System.out.println("===findFirst");
        var movie = movies.stream()
                .findFirst()
                .get();
        System.out.println(movie.getTitle());

        // return any movie obj
        System.out.println("===findAny");
        movie = movies.stream()
                .findAny()
                .get();
        System.out.println(movie.getTitle());

        System.out.println("===max");
        movie = movies.stream()
                .max(Comparator.comparing(Movie::getLikes))
                .get();
        System.out.println(movie.getTitle());

        System.out.println("===min");
        movie = movies.stream()
                .min(Comparator.comparing(Movie::getTitle))
                .get();
        System.out.println(movie.getTitle());
    }
}
